package com.xing.controller;

import com.xing.domain.User;
import com.xing.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/User")
public class UserController {
    @Autowired
    UserMapper userMapper;
    //查询全部用户
    @GetMapping("/queryList")
    public List<User> queryUser(){
        return userMapper.queryUserList();
    }
    //根据用户id查询用户
    @GetMapping("/queryUserById/{id}")
    public User queryUserById(@PathVariable("id") int id){
        return userMapper.queryUserById(id);
    }
    //添加用户数据
    @PostMapping("/addUser")
    public int addUser(@RequestBody User user){
        return userMapper.addUser(user);
    }
    //修改用户数据
    @PutMapping("/updateUser")
    public int updateUser(@RequestBody User user){
        return userMapper.updateUser(user);
    }
    //删除用户数据
    @DeleteMapping("/deleteUserById/{id}")
    public int deleteUserById(@PathVariable("id") int id){
        return userMapper.deleteUserById(id);
    }

}
